﻿
function GgLoad() {
    GgTimeLoad();
    //指数行情
    GetSSZhiShu();
}

function GgTimeLoad() {
    var code = $("#hidCode").val();
    $.getJSON("Handler/StockPrice.ashx", { ac: "g", code: code }, function (data) {
        if (data != null && data != "") {
            var str = "";
            str += '<div class=\"dp_ly_l1_1\">';
            str += '  <ul>';
            str += '    <li><span class=\"font20 heiti\">' + data.N + '</span>&nbsp;&nbsp;<span class=\"font14 font-weight\">' + data.C + '</span></li>';
            str += '    <li></li>';
            str += '    <li class=\"airal red font20\">' + UpDown3(data.P, data.F, 2, 1, "", "-") + '</li>';
            str += '    <li class=\"airal red font20\">' + UpDown4(data.D, data.F, 2, 1, "", "-") + '</li>';
            str += '    <li class=\"airal red font20\">' + UpDown4(data.F, data.F, 2, 1, "%", "-") + '</li>';
            if (data.flag < 0)
                str += '    <li><img src=\"images/btn_tp.jpg\" /></li>';

            str += '  </ul>';
            str += '</div>';
            str += '<div class=\"dp_time gray\">' + hqTime(data.T.toString(), 1) + '</div>';
            str += '<div class=\"stock_line\"></div>';
            str += '<div class=\"dp_ly_l1_2\">';
            str += '  <ul>';
            str += '    <li>开 盘：' + UpDown5(data.O, data.Y, 2, 1, "", "-") + '<br />';
            str += '      换 手：' + formatNumber(data.I, 2) + '手</li>';
            str += '    <li>最 高：' + UpDown5(data.H, data.Y, 2, 1, "", "-") + '<br />';
            str += '      市 盈：' + formatNumber(data.SY, 2) + '</li>';
            str += '    <li>最 低：' + UpDown5(data.L, data.Y, 2, 1, "", "-") + '<br />';
            str += '      量 比：' + formatNumber(data.LB, 2) + '%</li>';
            str += '    <li>昨 &nbsp;收：' + formatNumber(data.Y, 2) + '<br />';
            str += '      总市值：' + formatNumber(data.SZ / 100000000, 2) + '亿</li>';
            str += '    <li>成 交 量：' + formatNumber(data.V / 10000, 2) + '万手<br />';
            str += '      成交金额：' + formatNumber(data.A / 100000000, 2) + '亿</li>';
            str += '  </ul>';
            str += '</div>';
            $("#gghq").html(str);
        }
    })
}


//个股排行选项卡
function GgphTab(n) {
    $.get("Handler/StockPrice.ashx", { ac: "gg", m: n, aaa: Math.random() }, function (data) {
        $("#ggph").html(data);
        bindGgph();
    });
}

//绑定个股排行数据
function bindGgph() {
    var zxj = $("[zxj=zxj]");
    var zdf = $("[zdf=zdf]");
    var hsl = $("[hsl=hsl]");
    var cje = $("[cje=cje]");
    var bs = $("[bs=bs]");
    var codes = "";
    for (var i = 0; i < zxj.length; i++) {
        codes += $(zxj[i]).attr("code") + ",";
    }
    codes = codes.substring(0, codes.length - 1);

    $.getJSON("Handler/StockPrice.ashx", { ac: "g2", code: codes, aaa: Math.random() }, function (data) {
        $(data).each(function (i) {
            for (var j = 0; j < zxj.length; j++) {
                if ($(zxj[j]).attr("code") == data[i].C) {
                    $(zxj[i]).html(formatNumber(data[i].P, 2));
                    $(zdf[i]).html(UpDown(data[i].F, 2, 1, "%", "-"));
                    $(hsl[i]).html(UpDown(data[i].I, 2, 1, "", "-"));
                    $(cje[i]).html(formatNumber3(data[i].A, 10000, 2, "", "-"));
                    $(bs[i]).html(BSImg(data[i].NC, "-"));
                }
            }
        })
    })
}

//板块行情数据绑定
function bindBkhq() {
    var zdf = $("[bkzdf=bk1]");
    var zdf5 = $("[bkzdf5=bk1]");
    var zl = $("[bkzl=bk1]");
    var zl5 = $("[bkzl5=bk1]");
    var nc = $("[bknc=bk1]");
    var codes = "";
    for (var i = 0; i < zdf.length; i++) {
        codes += $(zdf[i]).attr("bkcode1") + ",";
    }
    codes = codes.substring(0, codes.length - 1);
    //alert(codes);
    $.getJSON("Handler/BkIfo.ashx", { ac: "bkhq", code: codes, aaa: Math.random() }, function (data) {
        $(data).each(function (i) {
            for (var j = 0; j < zdf.length; j++) {
                if ($(zdf[j]).attr("bkcode1") == data[i].C) {
                    $(zdf[j]).html(UpDown(data[i].F, 2, 1, "%", "-"));
                    $(zdf5[j]).html(UpDown(data[i].F5, 2, 1, "%", "-"));
                    $(zl[j]).html(formatNumber(data[i].I, 2));
                    $(zl5[j]).html(formatNumber(data[i].I5, 2));
                    if (data[i].NC>0)
                        $(nc[j]).html("<span title=\"发出B点买入信号" + Math.abs(data[i].NC) + "天\">" + Math.abs(data[i].NC) + "</span>");
                    else
                        $(nc[j]).html("<span title=\"发出S点卖出信号" + Math.abs(data[i].NC) + "天\">" + Math.abs(data[i].NC) + "</span>");
                    $(nc[j]).attr("className", data[i].NC < 0 ? "bg_tipG" : "bg_tipR");
                }
            }
        })
    })
}

//板块行情

function BkLoad() {
    //板块实时行情
    BkTimeLoad();
    //指数行情
    GetSSZhiShu();
}
//实时行情
function BkTimeLoad() {
    var code = $("#hidCode").val();
    $.getJSON("Handler/StockPrice.ashx", { ac: "bk", code: code, a: Math.round() }, function (data) {
        if (data != null && data != "") {
            var str = "";
            str += '<div class=\"dp_ly_l1_1\">';
            str += '  <ul>';
            str += '    <li><span class=\"font20 heiti\">' + data[0].N + '</span>&nbsp;&nbsp;<span class=\"font14 font-weight\">BK' + data[0].C.substr(2,4) + '</span></li>';
            str += '    <li></li>';
            str += '    <li class=\"airal red font20\">' + UpDown3(data[0].P, data[0].F, 2, 1, "", "-") + '</li>';
            str += '    <li class=\"airal red font20\">' + UpDown4(data[0].D, data[0].F, 2, 1, "", "-") + '</li>';
            str += '    <li class=\"airal red font20\">' + UpDown4(data[0].F, data[0].F, 2, 1, "%", "-") + '</li>';
            str += '  </ul>';
            str += '</div>';
            str += '<div class=\"dp_time gray\">' + hqTime(data[0].T.toString(), 1) + '</div>';
            str += '<div class=\"stock_line\"></div>';
            str += '<div class=\"dp_ly_l1_2\">';
            str += '  <ul>';
            str += '    <li>开 盘：' + UpDown5(data[0].O, data[0].Y, 2, 1, "", "-") + '<br />';
            str += '      换 手：' + formatNumber(data[0].I, 2) + '手</li>';
            str += '    <li>最 高：' + UpDown5(data[0].H, data[0].Y, 2, 1, "", "-") + '<br />';
            str += '      市 盈：' + formatNumber(data[0].SY, 2) + '</li>';
            str += '    <li>最 低：' + UpDown5(data[0].L, data[0].Y, 2, 1, "", "-") + '<br />';
            str += '      量 比：' + formatNumber(data[0].LB, 2) + '%</li>';
            str += '    <li>昨 &nbsp;收：' + formatNumber(data[0].Y, 2) + '<br />';
            str += '      总市值：' + formatNumber(data[0].SZ / 100000000, 2) + '亿</li>';
            str += '    <li>成 交 量：' + formatNumber(data[0].V / 10000, 2) + '万手<br />';
            str += '      成交金额：' + formatNumber(data[0].A / 100000000, 2) + '亿</li>';
            str += '  </ul>';
            str += '</div>';
            $("#bkhq").html(str);
        }
    })
}

function DpLoad() {
    //指数实时行情
    DpTimeLoad();
    //指数行情
    GetSSZhiShu();
}

//实时行情
function DpTimeLoad() {
    var code = $("#hidCode").val();
    $.getJSON("Handler/StockPrice.ashx", { ac: "dp", code: code, a: Math.round() }, function (data) {
        if (data != null && data != "") {
            var str = "";
            str += '<div class=\"dp_ly_l1_1\">';
            str += '  <ul>';
            str += '    <li><span class=\"font20 heiti\">' + data[0].N + '</span>&nbsp;&nbsp;<span class=\"font14 font-weight\">' + data[0].C + '</span></li>';
            str += '    <li></li>';
            str += '    <li class=\"airal red font20\">' + UpDown3(data[0].P, data[0].F, 2, 1, "", "-") + '</li>';
            str += '    <li class=\"airal red font20\">' + UpDown4(data[0].D, data[0].F, 2, 1, "", "-") + '</li>';
            str += '    <li class=\"airal red font20\">' + UpDown4(data[0].F, data[0].F, 2, 1, "%", "-") + '</li>';
            str += '  </ul>';
            str += '</div>';
            str += '<div class=\"dp_time gray\">' + hqTime(data[0].T.toString(), 1) + '</div>';
            str += '<div class=\"stock_line\"></div>';
            str += '<div class=\"dp_ly_l1_2\">';
            str += '  <ul>';
            str += '    <li>开 盘：' + UpDown5(data[0].O, data[0].Y, 2, 1, "", "-") + '<br />';
            str += '      成 交 量：' + formatNumber(data[0].V / 10000, 2) + '万手</li>';
            str += '    <li>最 高：' + UpDown5(data[0].H, data[0].Y, 2, 1, "", "-") + '<br />';
            str += '      成交金额：' + formatNumber(data[0].A / 100000000, 2) + '亿</li>';
            str += '    <li>最 低：' + UpDown5(data[0].L, data[0].Y, 2, 1, "", "-") + '<br />';
            str += '      振 幅：<span class=\"red\">' + formatNumber(data[0].LB, 2) + '%</span></li>';
            str += '    <li>昨 &nbsp;收：' + formatNumber(data[0].Y, 2) + '</li>';
            str += '  </ul>';
            str += '</div>';
            $("#bkhq").html(str);
        }
    })
}


function GetSSZhiShu() {
    $.get("Handler/StockPrice.ashx", { ac: "zhishu", aa: Math.random() }, function (data) {
        if (data != null) {
            $("#sszhishu").html(data);
        }
    });
}

//dtime 要格式的时间字符串
//f=1 返回yyyy-MM-dd HH:mm:ss 格式时间数据
function hqTime(dtime,f) {
    var rel = "";    
    if (dtime.length == 14) {
        switch (f) { 
            case 1:
                rel = dtime.substr(0, 4) + "-" + dtime.substr(4, 2) + "-" + dtime.substr(6, 2) + " " + dtime.substr(8, 2) + ":" + dtime.substr(10, 2) + ":" + dtime.substr(12, 2);
            break;
        }
}
    return rel;
}

//近期热点板块
function jqrdbk() {
    var obj0 = $("#hotbk ul:eq(0)");
    obj0.children("li:eq(0)").html("<img src=\"images/report_ico3.jpg\" />");
    obj0.children("li:eq(1)").attr("className", "sjgp_2");
    obj0.children("li:eq(2)").attr("className", "sjgp_2a");
    obj0.children("li:eq(3)").attr("className", "sjgp_2a");
    obj0.children("li:eq(4)").attr("className", "sjgp_1");
    obj0.next("div").attr("className", "sjgp_m report_bg");
    $("#hotbk ul").mouseover(function () {
        for (var i = 0; i < $("#hotbk ul").length; i++) {
            $("#hotbk ul:eq(" + i + ")").children("li:eq(0)").html("<img src=\"images/report_ico2.jpg\" />");
            $("#hotbk ul:eq(" + i + ")").children("li:eq(1)").attr("className", "sjgp_2 bottom_line");
            $("#hotbk ul:eq(" + i + ")").children("li:eq(2)").attr("className", "sjgp_2a bottom_line");
            $("#hotbk ul:eq(" + i + ")").children("li:eq(3)").attr("className", "sjgp_2a bottom_line");
            $("#hotbk ul:eq(" + i + ")").children("li:eq(4)").attr("className", "sjgp_1 bottom_line");
            $("#hotbk ul:eq(" + i + ")").next("div").attr("className", "sjgp_m report_bg hide");
        }
        $(this).children("li:eq(0)").html("<img src=\"images/report_ico3.jpg\" />");
        $(this).children("li:eq(1)").attr("className", "sjgp_2");
        $(this).children("li:eq(2)").attr("className", "sjgp_2a");
        $(this).children("li:eq(3)").attr("className", "sjgp_2a");
        $(this).children("li:eq(4)").attr("className", "sjgp_1");
        $(this).next("div").attr("className", "sjgp_m report_bg");
    });
}